import 'package:flutter/material.dart';
import 'package:net_store/DataSource/DataStore.dart';
import 'package:net_store/Pages/CategoryPage.dart';
import 'package:net_store/Pages/HomePage.dart';
import 'package:net_store/Pages/UserCenterPage.dart';
import 'package:net_store/main.dart';

class MainPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => MainPageState();
}

class MainPageState  extends State<MainPage> {

  var pageController = PageController(initialPage: 0);
  var pageIndex = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: Scaffold(
        body: PageView(
          onPageChanged: (index){
            setState(() {
              pageIndex = index;
            });
          },
          controller: pageController,
          children: <Widget>[
            HomePage(),
            CategoryPage(),
            UserCenterPage()
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: pageIndex,
          type: BottomNavigationBarType.shifting,
          onTap: (index){
            setState(() {
              pageIndex = index;
              pageController.animateToPage(pageIndex, duration: Duration(milliseconds: 500), curve: Curves.easeOutCirc);
            });
          },
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text("باش بەت"),
              backgroundColor: Colors.deepPurple
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.apps),
              title: Text("تۈرلەر"),
              backgroundColor: Color(0xff1A222F)
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.person),
                title: Text("مەن"),
              backgroundColor: Colors.blue
            ),
          ],
        ),
      ),
    );
  }
}